package com.shop.mapper;

import com.shop.pojo.Good;
import com.shop.pojo.Goods;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface GoodMapper {
    @Insert("insert into stable values(#{sid},#{sname},#{number},#{price},#{ppid},#{ffid},#{simgurl})")
    public int addGood(Good good);
    @Update("update stable set sname = #{sname},number = #{number}, price = #{price} , ppid = #{ppid}, ffid = #{ffid} ,simgurl = #{simgurl} where sid = #{sid}")
    public int updateGood(Good good);
    @Delete("delete from stable where sid = #{sid}")
    public int deleteGood(int sid);
//    @Select("select * from stable s,ftable f,ptable p where s.sname like \"%\"#{queryInfo}\"%\" and s.ppid = p.pid or s.ffid = f.fid")
    @Select("SELECT * FROM stable s,ftable f,ptable p WHERE  (s.ppid = p.pid AND s.ffid = f.fid) AND s.sname LIKE \"%\"#{queryInfo}\"%\" ")
    @Results({
            @Result(column = "sid",property = "sid"),
            @Result(column = "sname",property = "sname"),
            @Result(column = "number",property = "number"),
            @Result(column = "price",property = "price"),
            @Result(column = "ppid",property = "ppid"),
            @Result(column = "ffid",property = "ffid"),
            @Result(column = "simgurl",property = "simgurl"),
            @Result(column = "pid",property = "brand.pid"),
            @Result(column = "pname",property = "brand.pname"),
            @Result(column = "pimgurl",property = "brand.pimgurl"),
            @Result(column = "fid",property = "classify.fid"),
            @Result(column = "fname",property = "classify.fname"),
            @Result(column = "fatherId",property = "classify.fatherId")
    })
    public List<Goods> selectGood(String queryInfo);
    @Select("select count(*) from stable")
    public Integer selectCount();
    @Select("select * from stable where sid = #{sid}")
    public Good selectById(int sid);
}
